package com.blq.developtools.observerpattern.observable;

import android.net.DnsResolver;

import androidx.compose.foundation.layout.AlignmentLineProvider;

import com.blq.developtools.observerpattern.observer.ILayoutViewerActionObserve;

import java.util.Vector;
import java.util.function.Consumer;

import blq.ssnb.baseconfigure.splash.SqlTask;
import blq.ssnb.mvp.MvpCallBack;

/**
 * <pre>
 * ****************************************************************
 * 文件名称:LayoutViewerObservable.java
 * 作 者:SSNB
 * 创建时间:2024/5/24
 * 文件描述:
 * 注意事项:
 * 版权声明:Copyright (C) 2015-2025 杭州中焯信息技术股份有限公司
 * 修改历史:2024/5/24 1.00 初始版本
 * ****************************************************************
 * </pre>
 */
public class LayoutViewerObservable implements ILayoutViewerActionObserve {
    private static final LayoutViewerObservable ourInstance = new LayoutViewerObservable();

    public static LayoutViewerObservable getInstance() {
        return ourInstance;
    }

    private LayoutViewerObservable() {
        mObservers = new Vector<>();
    }
    private final Vector<ILayoutViewerActionObserve> mObservers;

    /**
     * 注册
     *
     * @param observe
     */
    public synchronized void registerNotify(ILayoutViewerActionObserve observe) {
        if (observe == null) {
            throw new NullPointerException();

        }
        if (!mObservers.contains(observe)) {
            mObservers.addElement(observe);
        }
    }

    /**
     * 反注册
     *
     * @param observe
     */
    public synchronized void unRegisterNotify(ILayoutViewerActionObserve observe) {
        mObservers.removeElement(observe);
    }

    /**
     * 清理
     */
    public synchronized void clearNotify() {
        mObservers.removeAllElements();
    }

    public synchronized int countObservers() {
        return mObservers.size();
    }

    @Override
    public void onLayoutInspectorStatus(boolean isOpen) {
        mObservers.forEach(bean -> bean.onLayoutInspectorStatus(isOpen));
    }

    @Override
    public void onLayoutViewerStatus(boolean isOpen) {
        mObservers.forEach(bean -> bean.onLayoutViewerStatus(isOpen));
    }

    @Override
    public void onLayoutViewerStatusChange(LayoutViewerStatus status) {
        mObservers.forEach(bean -> bean.onLayoutViewerStatusChange(status));
    }

}
